fix(docx-core): order-constrained TF-IDF paragraph matching prevents phantom redlines#62
Merged
stevenobiajulu merged 1 commit intomainfrom Mar 27, 2026
Merged
Conversation
…phantom redlines
Replace greedy Jaccard similarity fallback with two improvements:
1. Order-constrained gap matching: Pass 1 exact-hash anchors divide documents
into gaps. Pass 2 similarity matching is scoped to each gap via mini-LCS,
guaranteeing document order preservation.
2. TF-IDF cosine similarity: Replaces Jaccard, which over-weights common legal
boilerplate words ("holders", "Preferred Stock", "Corporation"). IDF
down-weights high-frequency terms; cosine similarity on TF-IDF vectors
produces more discriminating scores.
Root cause: the old greedy first-match algorithm iterated unmatched source
paragraphs in order, allowing early low-similarity matches to consume revised
paragraphs intended for higher-similarity matches later in the document. On
legal boilerplate (NVCA COI), this caused incorrect paragraph alignment,
garbled reject-all output, and fallback to the rebuild reconstruction path
with ~950 phantom insertions.
Fixes #61
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #61
Before: Greedy first-match allowed Source[45] (dividends) to steal Revised[20] (liquidation) via shared boilerplate → garbled reject-all → rebuild fallback → 949 phantom insertions
After: Gap constraints prevent cross-anchor matches; Source[50] correctly matches Revised[20] → inplace succeeds → 332 insertions, clean accept/reject round-trip
Test plan